<!--
 * @Author: 瞿旺兴 18774621495@163.com
 * @Date: 2022-06-11 11:02:19
 * @LastEditors: 瞿旺兴 18774621495@163.com
 * @LastEditTime: 2022-06-13 14:22:04
 * @FilePath: \nien-vue3-admin\src\components\dictSelect\index.vue
 * @Description: 带字典的select
-->
<template>
  <el-select-v2 v-bind="attrs" :options="options">
  </el-select-v2>
</template>

<script setup lang="ts">
import { computed, defineProps, useAttrs, withDefaults } from 'vue'
import useDicts, { DictDirection, dictInfo } from '@/store/modules/dicts'

const attrs = useAttrs()
const dicts = useDicts()
const props = withDefaults(defineProps<{
  dictsName:string;
  labelName?:string;
  valueName?:string;  
}>(),
{
  labelName: '',
  valueName: '',
}) 

dicts.setDicts(DictDirection[props.dictsName])

const options = computed(() => dicts[DictDirection[props.dictsName]]?.map(dict => ({
  value: dict[props.valueName || dictInfo[DictDirection[props.dictsName]]?.dictValue],
  label: dict[props.labelName || dictInfo[DictDirection[props.dictsName]]?.dictLabel],
})))

</script>
